package cn.jobstart.task;

import cn.jobstart.common.Const;
import cn.jobstart.common.redis.RedisUtil;
import cn.jobstart.model.Person;
import cn.jobstart.pubInter.AbstractTask;
import cn.jobstart.searchExt.PersonSearchExt;
import cn.jobstart.searchExt.ResumeBasicSearchExt;
import cn.jobstart.service.IPersonService;
import cn.jobstart.service.IResumeBasicService;
import cn.jobstart.vo.KeyValueVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author sunke
 * @version 1.0
 * @Description 统计人才数量
 * @date 2023-09-28 14:53
 */

@EnableScheduling
@Slf4j
@Component
public class PersonTask extends AbstractTask {

    @Resource
    private IResumeBasicService resumeBasicService;

    @Resource
    private IPersonService personService;


    @Resource
    private RedisUtil redisUtil;


    @Scheduled(cron = "0 0 03 * * ?")
   // @Scheduled(cron = "0 0/1 * * * ?")
    @Override
    public void run() {

        try {
            redisUtil.lRemoveAll(Const.REDIDS_KEY_PERSON);

            ResumeBasicSearchExt resumeBasicSearch = ResumeBasicSearchExt.getInstance();
            resumeBasicSearch.setCustomSql(" (rb_del_flag is null or rb_del_flag=0)");
            int resumeCount = resumeBasicService.getListCount(resumeBasicSearch);


            KeyValueVO valueVO = new KeyValueVO();
            valueVO.setKey("简历数量");
            valueVO.setValue(resumeCount);

            redisUtil.lSet(Const.REDIDS_KEY_PERSON, valueVO);


            PersonSearchExt personSearch = PersonSearchExt.getInstance();
            int personCount = personService.getListCount(personSearch);

            valueVO = new KeyValueVO();
            valueVO.setKey("人才数量");
            valueVO.setValue(personCount);

            redisUtil.lSet(Const.REDIDS_KEY_PERSON, valueVO);

            personSearch.setFieldNotNull(Person.PHONE);
            personCount = personService.getListCount(personSearch);
            valueVO = new KeyValueVO();
            valueVO.setKey("含手机号人才数量");
            valueVO.setValue(personCount);
            redisUtil.lSet(Const.REDIDS_KEY_PERSON, valueVO);


        } catch (Exception e) {

        }


    }
}
